//
//  FQAuditViewController.swift
//  SwiftProject
//
//  Created by 董駸 on 2023/4/12.
//

import UIKit

class FQAuditViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBarType = .light
    }
    
    override func initSubviews() {
        super.initSubviews()
        
        let auditV = FQAuditView(frame: .zero)
        view.addSubview(auditV)
        
        auditV.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(NavigationContentTop + 20)
            make.height.equalTo(300)
        }
        
        auditV.failBlock = { [unowned self] in
            self.showFail()
        }
    }
    
    func showFail() {
        let failImage = UIImageView(imageString: "icon_auditFail")
        view.addSubview(failImage)
        
        failImage.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(41 + NavigationContentTop)
        }
        
        let titleLb = QMUILabel(font: .rSFont(20), textColor: .colorMain)
        titleLb.text = "额度审核失败！"
        view.addSubview(titleLb)
        
        titleLb.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(failImage.snp.bottom)
        }
        
        let subTitleLb = QMUILabel(font: .rSFont(14), textColor: .color51)
        subTitleLb.text = "很抱歉，经过最新的综合评估，您本次提现操作\n暂时未通过提现审核，请过段时间再试"
        subTitleLb.numberOfLines = 0
        subTitleLb.textAlignment = .center
        view.addSubview(subTitleLb)
        
        subTitleLb.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(titleLb.snp.bottom).offset(14)
        }
        
        let whiteV = QMUILabel(font: .rSFont(13), textColor: .qmui_color(withHexString: "8e8e8e")!)
        whiteV.backgroundColor = .white
        whiteV.text = "1.30天内保证良好的信用记录；\n2.请继续保持社保公积金连续缴纳；\n3.请尽快处理当下不良逾期记录；\n4.30天内尽可能减少网贷申请次数。"
        whiteV.numberOfLines = 0
        whiteV.contentEdgeInsets = UIEdgeInsets(top: 8, left: 28, bottom: 8, right: 0)
        whiteV.textAlignment = .left
        whiteV.clipsToBounds = true
        whiteV.layer.cornerRadius = 8
        view.addSubview(whiteV)
        
        whiteV.snp.makeConstraints { make in
            make.centerX.equalToSuperview();
            make.top.equalTo(subTitleLb.snp.bottom).offset(40);
            make.size.equalTo(CGSizeMake(265, 110));
        }
        
        let confirmBtn = QMUIFillButton(fill: .colorMain, titleTextColor: .white)
        confirmBtn.titleLabel?.font = .bSFont(16)
        confirmBtn.setTitle("返回首页", for: .normal)
        confirmBtn.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
        view.addSubview(confirmBtn)
        
        confirmBtn.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 343~, height: 40~))
            make.centerX.equalToSuperview()
            make.top.equalTo(whiteV.snp.bottom).offset(100)
        }
    }
    
    @objc func buttonClick() {
        navigationController?.qmui_popToRootViewController(animated: true)
        CustomRelay.manager.tabbarStatusBehaviorRelay.accept(true)
    }
    
    override func setupNavigationItems() {
        super.setupNavigationItems()
        title = "额度审核"
    }

}
